﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using JumbotPay.API.Alipay.Mobile;
using Aop.Api;
using Aop.Api.Domain;
using Aop.Api.Request;
using Aop.Api.Response;

namespace JumbotPay.WebFile.Alipay_Mobile
{
    public partial class _default_step2 : JumbotPay.UI.BasicPage
    {
        public string account_alipay;
        public string Order_ID = "";
        public string Product_Name = "";
        public string Product_Desc = "";
        public string Order_Time = "";
        public string Order_Money = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            Order_ID = q("order_id");
            account_alipay = q("account_no");
            object[] _value = new JumbotPay.DAL.OrderDAL().GetOrderFields("alipay", Order_ID, "", "product_name,product_desc,pay_amount,Order_Time");
            Product_Name = _value[0].ToString();                            //商品名称
            Product_Desc = _value[1].ToString();                                 //商品描述
            string total_amount = _value[2].ToString();
            Order_Time = Convert.ToDateTime(_value[3].ToString()).ToString("yyyy-MM-dd HH:mm:ss");
            Order_Money = Str2Double(_value[2].ToString()).ToString("f2");

            Config conf = new Config(account_alipay);
            DefaultAopClient client = new DefaultAopClient(
                conf.gatewayUrl,
                conf.app_id,
                conf.private_key,
                "json",
                "1.0",
                conf.sign_type,
                conf.alipay_public_key,
                conf.charset,
                false);



            // 支付中途退出返回商户网站地址
            string quit_url = "http://www.knowfar.net.cn/";

            // 组装业务参数model
            AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
            model.Body = Product_Name;
            model.Subject = Product_Desc;
            model.TotalAmount = Str2Int(total_amount) == 88888 ? "0.01" : total_amount;//元
            model.OutTradeNo = Order_ID;
            model.ProductCode = "QUICK_WAP_WAY";
            model.QuitUrl = quit_url;

            AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
            // 设置支付完成同步回调地址
            request.SetReturnUrl(conf.return_url);
            // 设置支付完成异步通知接收地址
            request.SetNotifyUrl(conf.notify_url);
            // 将业务model载入到request
            request.SetBizModel(model);

            AlipayTradeWapPayResponse response = null;
            try
            {
                response = client.pageExecute(request, null, "post");
                Response.Write(response.Body);
            }
            catch (Exception exp)
            {
                throw exp;
            }


        }
    }
}
